from django.http import HttpResponse, Http404
from django.shortcuts import render, render_to_response, get_object_or_404
from .models import Article

# Create your views here.


def article_detail(request, article_id):
    try:
        article = Article.objects.get(id=article_id)
        context = {'article_obj': article}
        # return render(request, 'article_detail.html', context)
        return render_to_response('article_detail.html', context)
    except Article.DoesNotExist:
        raise Http404("Article does not exist")
    # return HttpResponse('article_title: %s<br>article_content: %s ' % (article.title, article.content))


def article_detail_less(request, article_id):
    article = get_object_or_404(Article, pk=article_id)
    context = {'article_obj': article}
    return render_to_response('article_detail.html', context)


def article_list(request):
    # articles = Article.objects.all()
    articles = Article.objects.filter(is_deleted=False)
    context = {'articles': articles}
    return render_to_response('article_list.html', context)
